package cn.com.cfae.iras.doc.analyze.components.integrity;

import cn.com.cfae.iras.doc.analyze.beans.web.Detail;
import cn.com.cfae.iras.doc.analyze.components.BaseComponent;
import cn.com.cfae.iras.doc.analyze.components.beans.ComponentResult;
import cn.com.cfae.iras.doc.analyze.handUtil.HandingData;
import cn.com.cfae.iras.doc.analyze.handUtil.SearchKeywordUtil;
import cn.com.cfae.iras.doc.analyze.parse.kv.KVText;
import cn.com.cfae.iras.doc.analyze.parse.model.*;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 架构完整性
 *
 * 1、检查募集说明书中对近一年或近一期收入占主营业务收入10%以上，或毛利润占10%的业务板块；
 * 2、检查主营板块是否含“行业现状”、“行业前景”、“行业政策”、“竞争格局”，不存在提示缺失；主营业务表
 *
 * 预评/发行阶段
 */
@Component("I1017")
@Scope("prototype")
public class I1017 extends BaseComponent {
    private static Logger log = LoggerFactory.getLogger(I1017.class);
    @Autowired
    private HandingData handingData;

    @Autowired
    private SearchKeywordUtil searchKeywordUtil;
    @Override
    public List<ComponentResult> handlerM() {
        log.info("获取I1017组件M");
        List<ComponentResult> componentResults = checkRulesI1017(getCatalogId(),getCatalogId(),getChapterId(),getRuleTitle());
        return componentResults;
    }

    @Override
    public List<ComponentResult> handlerBM() {
        return null;
    }

    @Override
    public List<ComponentResult> handlerDM() {
        log.info("获取I1017组件DM");
        List<ComponentResult> componentResults = checkRulesI1017(getCatalogId(),getCatalogId(),getChapterId(),getRuleTitle());
        return componentResults;
    }

    @Override
    public List<ComponentResult> handlerBDM() {
        return null;
    }

    private List<ComponentResult> checkRulesI1017(String model,String catalogId,String chapterId,String ruleName){
        DocumentModel extractData = super.getExtractData();
        List<ComponentResult> componentResults = new ArrayList<>();
        ComponentResult componentResult = null;
        ExtractItem extractItem = null;


        boolean flag = false;
        int startPageNum = 0;
        String[] keywords = new String[]{"行业现状","行业前景","行业政策","竞争格局"};
        Map<String,ExtractItem> businessMap = new HashMap<>();

        try {

            if (extractData!=null){
                ChapterModel chapterModel = extractData.getChapterModel(model);
                startPageNum =  chapterModel!=null?chapterModel.getStartPage():0;

                //营业收入
                Map<String, List<Map<String, ExtractItem>>> yysr = chapterModel.getModel("YYSR").getTables2();
                //毛利润
                Map<String, List<Map<String, ExtractItem>>> mlr = chapterModel.getModel("MLR").getTables2();

                //获取主营业务

                List<Map<String,ExtractItem>> yysrBusinesses = null;
                List<Map<String,ExtractItem>> mlrBusinesses = null;
                if (yysr!=null){
                    yysrBusinesses = getBusiness(yysr);
                }
                if (mlr!=null){
                    mlrBusinesses = getBusiness(mlr);
                }
                //行业去重
                if (CollectionUtils.isNotEmpty(yysrBusinesses)&&CollectionUtils.isNotEmpty(mlrBusinesses)){
                    for (Map<String,ExtractItem> yysrMap : yysrBusinesses){
                        for (String key:yysrMap.keySet()){
                            businessMap.put(key,yysrMap.get(key));
                        }
                    }
                    for (Map<String,ExtractItem> mlrMap : mlrBusinesses){
                        for (String key:mlrMap.keySet()){
                            businessMap.put(key,mlrMap.get(key));
                        }
                    }
                }else if (CollectionUtils.isNotEmpty(yysrBusinesses)&&CollectionUtils.isEmpty(mlrBusinesses)){
                    for (Map<String,ExtractItem> yysrMap : yysrBusinesses){
                        for (String key:yysrMap.keySet()){
                            businessMap.put(key,yysrMap.get(key));
                        }
                    }
                }else if (CollectionUtils.isEmpty(yysrBusinesses)&&CollectionUtils.isNotEmpty(mlrBusinesses)){
                    for (Map<String,ExtractItem> mlrMap : mlrBusinesses){
                        for (String key:mlrMap.keySet()){
                            businessMap.put(key,mlrMap.get(key));
                        }
                    }
                }
                /*if (!businessMap.isEmpty()){
                    int bkPageNum = 0;
                    List<ComponentResult.TextPosition> bkContentAndPositionList = null;
                    for (String bk:businessMap.keySet()){
                        ExtractItem bkExtractItem = businessMap.get(bk);
                        if (bkExtractItem!=null){
                            KVText value = bkExtractItem.getValue();
                            bkPageNum = value!=null?value.getPageNumber():startPageNum;
                            bkContentAndPositionList = value!=null?getContentAndPositionList(value):null;
                        }
                        componentResult = handingData.getComponentResult(catalogId,chapterId,ruleName,"主要业务板块行业现状等相关内容检查:"+bk,"已抽取",false,getRegulationId(),bkPageNum,bkContentAndPositionList,"01");
                        componentResults.add(componentResult);
                    }
                    flag = true;
                }else {
                    componentResult = handingData.getComponentResult(catalogId,chapterId,ruleName,"主要业务板块行业现状等相关内容检查","未识别,建议人工核对",true,getRegulationId(),startPageNum,contentAndPositionList,"03");
                    componentResults.add(componentResult);*//*
                }
*/


                //在此页码区间检查文本内容
                //首先获取行业板块
                if (businessMap!=null&&!businessMap.isEmpty()){


                    //获取到主营业务板块页数；
                    int zyywStartPage  = startPageNum;
                    int zywyEndPage = 0;
                    List<SectionModel> sectionModelList = chapterModel.getSectionModelList();
                    Map<String, Object> zyywPage = searchKeywordUtil.getSectionTitlePageFromStartPage(sectionModelList, "主营业务,发行人业务状况,发行人业务范围,发行人经营情况",startPageNum,0);
                    if (zyywPage!=null&&(boolean)zyywPage.get("flag")){
                        zyywStartPage = (int) zyywPage.get("startPage");
                        zywyEndPage = (int) zyywPage.get("endPage");
                    }

                    String hyzcRegex = "行业政策";
                    String hyxzRegex = "行业现状,行业状况,行业概况,行业情况,整体概况";
                    String hyqjRegex = "行业前景,未来发展趋势,行业未来发展趋势,行业趋势,行业发展前景";
                    String jzgjRegex = "竞争格局,竞争状况,行业竞争,竞争优势,行业地位";
                    int pageNum = 0;
                    Map<String, Object> hyzcContains = null;
                    for (String key:businessMap.keySet()){
                        boolean hyxzFlag = false;
                        boolean hyqjFlag = false;
                        boolean hyzcFlag = false;
                        boolean jzgjFlag = false;


                        Map<String, Object> thirdTitlePageFromStartPage = searchKeywordUtil.getThirdTitlePageFromStartPage(sectionModelList, key, zyywStartPage, zywyEndPage);

                        if (thirdTitlePageFromStartPage!=null&&(boolean)thirdTitlePageFromStartPage.get("flag")){
                          int  thirdStartPage = (int) thirdTitlePageFromStartPage.get("startPage");
                          thirdStartPage = thirdStartPage!=0?thirdStartPage:zyywStartPage;
                          int thirdEndPage = (int) thirdTitlePageFromStartPage.get("endPage");
                          thirdEndPage = thirdStartPage!=0?thirdEndPage:zywyEndPage;
                            List<ComponentResult.TextPosition>  contentAndPositionList = ( List<ComponentResult.TextPosition>)thirdTitlePageFromStartPage.get("textPositions");

                            List<PageModel> pageModelList = chapterModel.getPageModelList();
                            if (CollectionUtils.isNotEmpty(pageModelList)){
                                for (PageModel pageModel :pageModelList){
                                    pageNum = pageModel.getPageNumber();
                                    pageNum = pageNum!=0?pageNum:thirdStartPage;
                                    if (pageNum<thirdStartPage){
                                        continue;
                                    }
                                    if (pageNum>thirdEndPage){
                                        break;
                                    }
                                    JsonElement jsonTextData = pageModel.getJsonTextData();
                                    if (!hyzcFlag){
                                        hyzcContains = searchKeywordUtil.isContainsKeywords2LiensOfSynonyms(jsonTextData, hyzcRegex,pageModel);
                                        if ((boolean) hyzcContains.get("flag")){
                                            List<ComponentResult.TextPosition> thirdContentAndPositionList = ( List<ComponentResult.TextPosition> ) hyzcContains.get("position");
                                            componentResult =  handingData.getComponentResult(catalogId,chapterId,ruleName,"主营业务板块相关内容检查:"+key+",关键词检查-行业政策","正确",false,getRegulationId(),pageNum,thirdContentAndPositionList,"01");
                                            componentResults.add(componentResult);
                                            hyzcFlag = true;
                                        }
                                    }
                                    if (!hyxzFlag){
                                        hyzcContains = searchKeywordUtil.isContainsKeywords2LiensOfSynonyms(jsonTextData, hyxzRegex,pageModel);
                                        if ((boolean) hyzcContains.get("flag")){
                                            List<ComponentResult.TextPosition> thirdContentAndPositionList = ( List<ComponentResult.TextPosition> ) hyzcContains.get("position");
                                            componentResult =  handingData.getComponentResult(catalogId,chapterId,ruleName,"主营业务板块相关内容检查:"+key+",关键词检查-行业现状","正确",false,getRegulationId(),pageNum,thirdContentAndPositionList,"01");
                                            componentResults.add(componentResult);
                                            hyxzFlag =  true;
                                        }
                                    }


                                    if (!hyqjFlag){
                                        hyzcContains = searchKeywordUtil.isContainsKeywords2LiensOfSynonyms(jsonTextData, hyqjRegex,pageModel);
                                        if ((boolean) hyzcContains.get("flag")){
                                            List<ComponentResult.TextPosition> thirdContentAndPositionList = ( List<ComponentResult.TextPosition> ) hyzcContains.get("position");
                                            componentResult =  handingData.getComponentResult(catalogId,chapterId,ruleName,"主营业务板块相关内容检查:"+key+",关键词检查-行业前景","正确",false,getRegulationId(),pageNum,thirdContentAndPositionList,"01");
                                            componentResults.add(componentResult);
                                            hyqjFlag =  true;
                                        }
                                    }


                                    if (!jzgjFlag){
                                        hyzcContains = searchKeywordUtil.isContainsKeywords2LiensOfSynonyms(jsonTextData, jzgjRegex,pageModel);
                                        if ((boolean) hyzcContains.get("flag")){
                                            List<ComponentResult.TextPosition> thirdContentAndPositionList = ( List<ComponentResult.TextPosition> ) hyzcContains.get("position");
                                            componentResult =  handingData.getComponentResult(catalogId,chapterId,ruleName,"主营业务板块相关内容检查:"+key+",关键词检查-竞争格局","正确",false,getRegulationId(),pageNum,thirdContentAndPositionList,"01");
                                            componentResults.add(componentResult);
                                            jzgjFlag =  true;
                                        }
                                    }

                                }


                                if (!hyxzFlag){
                                    componentResult =  handingData.getComponentResult(catalogId,chapterId,ruleName,"主营业务板块相关内容检查:"+key+",关键词检查-行业现状","缺失",true,getRegulationId(),thirdStartPage,contentAndPositionList,"02");
                                    componentResults.add(componentResult);

                                }
                                if (!hyqjFlag){
                                    componentResult =  handingData.getComponentResult(catalogId,chapterId,ruleName,"主营业务板块相关内容检查:"+key+",关键词检查-行业前景","缺失",true,getRegulationId(),thirdStartPage,contentAndPositionList,"02");
                                    componentResults.add(componentResult);

                                }
                                if (!hyzcFlag){
                                    componentResult =  handingData.getComponentResult(catalogId,chapterId,ruleName,"主营业务板块相关内容检查:"+key+",关键词检查-行业政策","缺失",true,getRegulationId(),thirdStartPage,contentAndPositionList,"02");
                                    componentResults.add(componentResult);

                                }
                                if (!jzgjFlag){
                                    componentResult =  handingData.getComponentResult(catalogId,chapterId,ruleName,"主营业务板块相关内容检查:"+key+",关键词检查-竞争格局","缺失",true,getRegulationId(),thirdStartPage,contentAndPositionList,"02");
                                    componentResults.add(componentResult);

                                }
                            }
                        }else {
                            componentResult = handingData.getComponentResult(catalogId,chapterId,ruleName,"主营业务板块相关内容检查:"+key,"未抽取到主要行业板块，建议人工核对",true,getRegulationId(),zyywStartPage,null,"03");
                            componentResults.add(componentResult);
                            for (String kw :keywords){
                                componentResult = handingData.getComponentResult(catalogId,chapterId,ruleName,"主营业务板块相关内容检查:"+key+",关键词检查-"+kw,"未触发检查",true,getRegulationId(),zyywStartPage,null,"03");
                                componentResults.add(componentResult);
                            }
                        }

                    }


                }else {
                    componentResult = handingData.getComponentResult(catalogId,chapterId,ruleName,"主营业务板块相关内容检查","未抽取到主要行业板块，建议人工核对",true,getRegulationId(),startPageNum,null,"03");
                    componentResults.add(componentResult);
                    for (String key :keywords){
                        componentResult = handingData.getComponentResult(catalogId,chapterId,ruleName,"主营业务板块相关内容检查,关键词检查-"+key,"未触发检查",true,getRegulationId(),startPageNum,null,"03");
                        componentResults.add(componentResult);
                    }

                }






               /* if (businessMap!=null&&!businessMap.isEmpty()){

                    for (String key:businessMap.keySet()){
                        List<ComponentResult> resuls = getCompontentResultOfHy(chapterModel, key, catalogId, chapterId, ruleName, startPageNum);
                        componentResults.addAll(resuls);
                    }

                }else {
                    componentResult = handingData.getComponentResult(catalogId,chapterId,ruleName,"主要业务板块行业现状等相关内容检查","未抽取到主要行业板块，建议人工核对",true,getRegulationId(),startPageNum,contentAndPositionList,"03");
                    componentResults.add(componentResult);
                    for (String key :keywords){
                        componentResult = handingData.getComponentResult(catalogId,chapterId,ruleName,"主要业务板块行业现状等相关内容检查,关键词检查-"+key,"未触发检查",true,getRegulationId(),startPageNum,null,"03");
                        componentResults.add(componentResult);
                    }
                    *//*for (String hy:businessMap.keySet()){
                        for (String key :keywords){
                            componentResult = handingData.getComponentResult(catalogId,chapterId,ruleName,"主要业务板块行业现状等相关内容检查:"+hy+",关键词检查-"+key,"未触发检查",true,getRegulationId(),startPageNum,contentAndPositionList,"03");
                            componentResults.add(componentResult);
                        }
                    }*//*
                }*/
            }

            boolean isAllErr = false;
            if (CollectionUtils.isNotEmpty(componentResults)){
                for (ComponentResult result :componentResults){
                    if (result.getExist().equals("02")){
                        isAllErr = true;
                        break;
                    }
                }
                if (isAllErr){
                    for (ComponentResult result :componentResults){
                        result.setExist("02");
                    }
                }

            }

        }catch (Exception e){
            componentResults.clear();
            componentResult = handingData.getComponentResult(catalogId,chapterId,ruleName,"主营业务板块相关内容检查","未识别,建议人工核对",true,getRegulationId(),startPageNum,null,"03");
            componentResults.add(componentResult);

            for (String key :keywords){
                componentResult = handingData.getComponentResult(catalogId,chapterId,ruleName,"主营业务板块相关内容检查,关键词检查-"+key,"未触发检查",true,getRegulationId(),startPageNum,null,"03");
                componentResults.add(componentResult);
            }

             log.error(e.getMessage(),e);
        }

        return componentResults;
    }

    private List<Map<String,ExtractItem>>  getBusiness(Map<String, List<Map<String, ExtractItem>>> table){
        String regex = ".*[\\u4e00-\\u9fa5].*";
        Pattern pattern = Pattern.compile(regex);

        List<Map<String,ExtractItem>> resultList = new ArrayList<>();
        if (table.isEmpty())
            return resultList;
        String yearJYQ = getYearJYQ(table);
        for (Map.Entry<String, List<Map<String, ExtractItem>>> entry : table.entrySet()) {
            if (StringUtils.isNotEmpty(yearJYQ)&&entry.getKey().equals(yearJYQ)){
                List<Map<String, ExtractItem>> value = entry.getValue();
                if (CollectionUtils.isNotEmpty(value)){
                    for (Map<String, ExtractItem> map : value){
                        Map<String,ExtractItem> resultMap = new HashMap<>();
                        for (String row:map.keySet()){
                            if ("ZB".equals(row)){
                                ExtractItem extractItem = map.get(row);
                                if (extractItem!=null){
                                    KVText kvValue = extractItem.getValue();
                                    String text = kvValue!=null?kvValue.getText():null;

                                    if (StringUtils.isNotEmpty(text)){
                                        Matcher m = pattern.matcher(text);
                                        if (m.matches()){
                                            continue;
                                        }

                                        text = StringUtils.isNotEmpty(text)?text.replaceAll("\\s",""):null;
                                        if (StringUtils.isNotEmpty(text)&&text.contains("%"))
                                            text = text.replaceAll("%","");
                                        if (StringUtils.isNotEmpty(text)&&text.contains(","))
                                            text = text.replaceAll(",","");
                                        if (StringUtils.isNotEmpty(text)&&text.contains("."))
                                            text = text.substring(0,text.indexOf("."));

                                        int textInt = Integer.parseInt(text);
                                        if (textInt>=10){
                                            ExtractItem ywbkExtractItem = map.get("YWBK");
                                            if (ywbkExtractItem!=null){
                                                KVText ywbkTextVelue = ywbkExtractItem.getValue();
                                                String ywbkText = ywbkTextVelue!=null?ywbkTextVelue.getText():null;
                                                if (ywbkText.contains("合")||ywbkText.contains("总"))
                                                    continue;
                                                resultMap.put(ywbkText,extractItem);
                                            }
                                            resultList.add(resultMap);
                                        }
                                    }


                                }
                                break;
                            }
                        }
                    }
                }
                break;
            }

        }
        return resultList;
    }

    private String getYearJYQ(Map<String, List<Map<String, ExtractItem>>> table){
        List<String> years = new ArrayList<>();
        String yearJyq = null;
        if (table.isEmpty()){
            return yearJyq;
        }

        for (String year :table.keySet()){
            years.add(year);
        }
        if (CollectionUtils.isNotEmpty(years)){
            Collections.sort(years);
            yearJyq = years.get(years.size()-1);
        }

        return yearJyq;
    }

    private List<ComponentResult> getCompontentResultOfHy(ChapterModel chapterModel,String hy,String catalogId,String chapterId,String ruleName,int startPage){
        Double x = 0.0;
        Double y = 0.0;
        List<ComponentResult> componentResults = new ArrayList<>();
        ComponentResult componentResult = null;

        ComponentResult.TextPosition contentAndPosition =null;
        List<PageModel> pageModelList = chapterModel.getPageModelList();
        int pageNum = 0;
        boolean hyxzFlag = false;
        boolean hyqjFlag = false;
        boolean hyzcFlag = false;
        boolean jzgjFlag = false;
        boolean isBusinessExest = false;
        Pattern pattern = null;
        Matcher matcher = null;
        String hyzcRegex = ".*行业政策.*";
        String hyxzRegex = ".*(行业现状|行业状况|行业概况|行业情况|整体概况).*";
        String hyqjRegex = ".*(行业前景|未来发展趋势|行业未来发展趋势|行业趋势|行业发展前景).*";
        String jzgjRegex = ".*(竞争格局|竞争状况|行业竞争|竞争优势|行业地位).*";
        if (CollectionUtils.isNotEmpty(pageModelList)){


            for (PageModel pageModel : pageModelList) {
                JsonElement jsonTextData = pageModel.getJsonTextData();
                if (!jsonTextData.isJsonNull()){
                    JsonArray jsonArray = jsonTextData.getAsJsonArray();
                    if (!jsonArray.isJsonNull()){
                        for (int i=0;i<jsonArray.size();i++){
                            JsonObject asJsonObject = jsonArray.get(i).getAsJsonObject();
                            Set set = asJsonObject.entrySet();
                            Iterator<Map.Entry<String, JsonElement>> it = set.iterator();
                            String key ;

                            while (it.hasNext()){
                                //每一页data数据
                                Map.Entry<String, JsonElement> entry = it.next();
                                key= entry.getKey();
                                if (StringUtils.isNotEmpty(key)&&key.equals("data")){
                                    JsonArray dataJsonArray = null;
                                    if (entry.getValue().isJsonArray()){
                                        dataJsonArray  = entry.getValue().getAsJsonArray();
                                    }
                                    if (!dataJsonArray.isJsonNull()){

                                        for (int d=0; d<dataJsonArray.size(); d++){
                                            JsonArray delmJsonArray = dataJsonArray.get(d).getAsJsonArray();
                                            if (!dataJsonArray.isJsonNull()){
                                                for (int de=0;de<delmJsonArray.size();de++){
                                                    JsonObject deJsonObject = delmJsonArray.get(de).getAsJsonObject();
                                                    Set deSet = deJsonObject.entrySet();
                                                    Iterator<Map.Entry<String, JsonElement>> deIt = deSet.iterator();
                                                    while (deIt.hasNext()){
                                                        Map.Entry<String, JsonElement> deEntry = deIt.next();
                                                        String deKey= deEntry.getKey();
                                                        if (StringUtils.isNotEmpty(deKey)&&deKey.equals("top")){
                                                            y = deEntry.getValue()!=null?deEntry.getValue().getAsDouble():0.0;
                                                        }
                                                        if (StringUtils.isNotEmpty(deKey)&&deKey.equals("left")){
                                                            x = deEntry.getValue()!=null?deEntry.getValue().getAsDouble():0.0;
                                                        }

                                                        if (StringUtils.isNotEmpty(deKey)&&deKey.equals("text")){
                                                            String count = deEntry.getValue().getAsString();
                                                            if (!isBusinessExest){
                                                                if (StringUtils.isNotEmpty(count)){
                                                                    String hyRegex = ".*"+hy+".*";
                                                                    pattern = Pattern.compile(hyRegex);
                                                                    matcher = pattern.matcher(count);
                                                                    if (matcher.matches()){
                                                                        isBusinessExest =true;
                                                                    }
                                                                }
                                                            }

                                                            if (isBusinessExest&&!hyxzFlag){
                                                                if (StringUtils.isNotEmpty(count)){
                                                                    pattern = Pattern.compile(hyxzRegex);
                                                                    matcher = pattern.matcher(count);
                                                                    if (matcher.matches()){
                                                                        List<ComponentResult.TextPosition> contentAndPositionList =new ArrayList<>();
                                                                        hyxzFlag = true;
                                                                        pageNum = 0;
                                                                        pageNum = pageModel.getPageNumber();
                                                                        contentAndPosition =  new ComponentResult().new TextPosition();
                                                                        contentAndPosition.setX(x);
                                                                        contentAndPosition.setY(y);
                                                                        contentAndPosition.setContent(count);
                                                                        contentAndPositionList.add(contentAndPosition);
                                                                        componentResult =  handingData.getComponentResult(catalogId,chapterId,ruleName,"主要业务板块行业现状等相关内容检查:"+hy+",关键词检查-行业现状","正确",false,getRegulationId(),pageNum,contentAndPositionList,"01");
                                                                        componentResults.add(componentResult);
                                                                    }
                                                                }
                                                            }
                                                            if (isBusinessExest&&!hyqjFlag){
                                                                if (StringUtils.isNotEmpty(count)){
                                                                    pattern = Pattern.compile(hyqjRegex);
                                                                    matcher = pattern.matcher(count);
                                                                    if (matcher.matches()){
                                                                        List<ComponentResult.TextPosition> contentAndPositionList =new ArrayList<>();
                                                                        hyqjFlag = true;
                                                                        pageNum = pageModel.getPageNumber();
                                                                        contentAndPosition =  new ComponentResult().new TextPosition();
                                                                        contentAndPosition.setX(x);
                                                                        contentAndPosition.setY(y);
                                                                        contentAndPosition.setContent(count);
                                                                        contentAndPositionList.add(contentAndPosition);
                                                                        componentResult =  handingData.getComponentResult(catalogId,chapterId,ruleName,"主要业务板块行业现状等相关内容检查:"+hy+",关键词检查-行业前景","正确",false,getRegulationId(),pageNum,contentAndPositionList,"01");
                                                                        componentResults.add(componentResult);
                                                                    }
                                                                }
                                                            }

                                                            if (isBusinessExest&&!hyzcFlag){
                                                                if (StringUtils.isNotEmpty(count)){
                                                                    pattern = Pattern.compile(hyzcRegex);
                                                                    matcher = pattern.matcher(count);
                                                                    if (matcher.matches()){
                                                                        List<ComponentResult.TextPosition> contentAndPositionList =new ArrayList<>();
                                                                        hyzcFlag = true;
                                                                        pageNum = pageModel.getPageNumber();
                                                                        contentAndPosition =  new ComponentResult().new TextPosition();
                                                                        contentAndPosition.setX(x);
                                                                        contentAndPosition.setY(y);
                                                                        contentAndPosition.setContent(count);
                                                                        contentAndPositionList.add(contentAndPosition);
                                                                        componentResult =  handingData.getComponentResult(catalogId,chapterId,ruleName,"主要业务板块行业现状等相关内容检查:"+hy+",关键词检查-行业政策","正确",false,getRegulationId(),pageNum,contentAndPositionList,"01");
                                                                        componentResults.add(componentResult);
                                                                    }
                                                                }

                                                            }
                                                            if (isBusinessExest&&!jzgjFlag){
                                                                if (StringUtils.isNotEmpty(count)){
                                                                    pattern = Pattern.compile(jzgjRegex);
                                                                    matcher = pattern.matcher(count);
                                                                    if (matcher.matches()){
                                                                        List<ComponentResult.TextPosition> contentAndPositionList =new ArrayList<>();
                                                                        jzgjFlag = true;
                                                                        pageNum = pageModel.getPageNumber();
                                                                        contentAndPosition =  new ComponentResult().new TextPosition();
                                                                        contentAndPosition.setX(x);
                                                                        contentAndPosition.setY(y);
                                                                        contentAndPosition.setContent(count);
                                                                        contentAndPositionList.add(contentAndPosition);
                                                                        componentResult =  handingData.getComponentResult(catalogId,chapterId,ruleName,"主要业务板块行业现状等相关内容检查:"+hy+",关键词检查-竞争格局","正确",false,getRegulationId(),pageNum,contentAndPositionList,"01");
                                                                        componentResults.add(componentResult);
                                                                    }
                                                                }

                                                            }

                                                        }
                                                    }

                                                    if (isBusinessExest&&hyxzFlag&&hyqjFlag&&hyzcFlag&&jzgjFlag){
                                                        break;
                                                    }
                                                }
                                            }
                                            if (isBusinessExest&&hyxzFlag&&hyqjFlag&&hyzcFlag&&jzgjFlag){
                                                break;
                                            }
                                        }
                                    }
                                }
                                if (isBusinessExest&&hyxzFlag&&hyqjFlag&&hyzcFlag&&jzgjFlag){
                                    break;
                                }
                            }
                            if (isBusinessExest&&hyxzFlag&&hyqjFlag&&hyzcFlag&&jzgjFlag){
                                break;
                            }
                        }
                    }
                }
                if (isBusinessExest&&hyxzFlag&&hyqjFlag&&hyzcFlag&&jzgjFlag){
                    break;
                }
            }
        }
        if (!hyxzFlag){
            componentResult =  handingData.getComponentResult(catalogId,chapterId,ruleName,"主要业务板块行业现状等相关内容检查:"+hy+",关键词检查-行业现状","缺失",true,getRegulationId(),startPage,null,"02");
            componentResults.add(componentResult);

        }
        if (!hyqjFlag){
            componentResult =  handingData.getComponentResult(catalogId,chapterId,ruleName,"主要业务板块行业现状等相关内容检查:"+hy+",关键词检查-行业前景","缺失",true,getRegulationId(),startPage,null,"02");
            componentResults.add(componentResult);

        }
        if (!hyzcFlag){
            componentResult =  handingData.getComponentResult(catalogId,chapterId,ruleName,"主要业务板块行业现状等相关内容检查:"+hy+",关键词检查-行业政策","缺失",true,getRegulationId(),startPage,null,"02");
            componentResults.add(componentResult);

        }
        if (!jzgjFlag){
            componentResult =  handingData.getComponentResult(catalogId,chapterId,ruleName,"主要业务板块行业现状等相关内容检查:"+hy+",关键词检查-竞争格局","缺失",true,getRegulationId(),startPage,null,"02");
            componentResults.add(componentResult);

        }

        return  componentResults;
    }

}
